package com.car.controller;


import com.car.entity.Comment;
import com.car.service.ICommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class CommentController {


    @Autowired
    @Qualifier(value = "commentService")
    private ICommentService commentService;
    @RequestMapping("/AAll")
    public String findAll(Model model,
                          @RequestParam(defaultValue ="1")Integer pageNum,
                          @RequestParam(defaultValue = "2")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> all = commentService.findAll(pageNum, pageSize);
        PageInfo<Comment> pageInfo = new PageInfo<>(all);
        model.addAttribute("pageInfo",pageInfo);
        return "Comment.jsp";
    }
    @RequestMapping(value = "/AID")
    public String findById(Model model,
                           int order_id){
        Comment byId = commentService.findById(order_id);
        model.addAttribute("b",byId);
        return "view_Comment.jsp";
    }

    @RequestMapping("/At")
    public String findtatus(Model model,String point,
                            @RequestParam(defaultValue ="1")Integer pageNum,
                            @RequestParam(defaultValue = "2")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> tatus = commentService.findtatus(point);
        PageInfo<Comment> pageInfo = new PageInfo<>(tatus);
        model.addAttribute("pageInfo",pageInfo);
        return  "Comment.jsp";
    }

    @RequestMapping("/AS")
    public String findStatus(Model model,String point,
                             @RequestParam(defaultValue ="1")Integer pageNum,
                             @RequestParam(defaultValue = "2")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> status = commentService.findStatus(point);
        PageInfo<Comment> pageInfo = new PageInfo<>(status);
        model.addAttribute("pageInfo",pageInfo);
        return  "Comment.jsp";
    }

}
